JavaScript JS Tutorial JS Objects JS Functions JS Classes JS Async JS HTML DOM JS Browser BOM JS Web APIs JS AJAX JS JSON JS vs jQuery JS Graphics



DOM CSS

Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language. CSS is used to style HTML and XML documents. The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. CSS and DOM are two important technologies used in web development.

Brief Explanation of DOM CSS

The DOM is a hierarchical tree-like structure that represents the HTML or XML document. Each element in the document is represented by a node in the tree. The DOM provides a way to access and manipulate the nodes in the tree using JavaScript. CSS is used to style the nodes in the DOM tree. CSS can be applied to individual elements, groups of elements, or the entire document. CSS can be used to change the color, font, size, and layout of the elements in the document.

Code Examples

Here are some examples of how CSS can be used to style the DOM:

Changing the Background Color

To change the background color of an element, use the background-color property:

<style>
  p {
    background-color: yellow;
  }
</style>

<p>This paragraph has a yellow background color.</p>

Changing the Font Size

To change the font size of an element, use the font-size property:

<style>
  p {
    font-size: 24px;
  }
</style>

<p>This paragraph has a font size of 24 pixels.</p>

Changing the Text Color

To change the text color of an element, use the color property:

<style>
  p {
    color: red;
  }
</style>

<p>This paragraph has red text.</p>

Changing the Border

To add a border to an element, use the border property:

<style>
  p {
    border: 1px solid black;
  }
</style>

<p>This paragraph has a black border.</p>

Changing the Layout

To change the layout of an element, use the display property:

<style>
  p {
    display: inline-block;
  }
</style>

<p>This paragraph is displayed as an inline block.</p>

References

Activity