Generally speaking, in the world of web programming, styles and attributes are defined through CSS and HTML. If we analyze and examine the structural framework of web pages, we can understand the core concepts of CSSOM and DOM. At first glance, these two may seem similar, but each serves its own specific role and function. In this article, we aim to investigate this area, particularly which of these two structures is considered inline styling.
DOM, or Document Object Model, represents a structure of HTML content that includes all the elements of a web page. In other words, the DOM is a tree structure of elements showing the content of a web page and allowing us to interact with it through scripts and various capabilities.
On the other hand, CSSOM, or CSS Object Model, represents a structure of the CSS code provided by us. Although this model might not be as recognizable as DOM, it plays a very important role in rendering web pages and is directly related to the styling of elements.
The question that arises is: Inline styles that are directly written within HTML tags, which of these two models do they belong to? The answer is that inline styling is considered a part of DOM since these styles are applied directly and without any intermediary on top of HTML elements.
Sample Code
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example Inline Styling</title>
</head>
<body>
<div style="color: red; font-size: 20px;">This is a text with inline style</div>
</body>
</html>
Explanation of Code
<!DOCTYPE html>
defines the document type of HTML<html lang="fa">
starts the HTML document with Persian language<meta charset="UTF-8">
defines the character set to UTF-8<meta name="viewport" content="width=device-width, initial-scale=1.0">
sets the display of the page in a responsive way<title>Example Inline Styling</title>
the title displayed in the browser tab<body>
begins the main content of the page<div style="color: red; font-size: 20px;">This is a text with inline style</div>
defines a div block with directly applied inline style</body>
ends the main content of the page</html>
ends the HTML document