Languages
[Edit]
EN

CSS - use element id in style selector

0 points
Created by:
Palpys
464

In this article, we would like to show you how to use element id in style selector using CSS.

Quick solution:

#elemet-id { 
  /* style properties here */
}

 

Practical example

In this example, we create the style for elements with id = my-element, then we assign the style to the my-element inside body section using id property.

Note:

Styling using id property isn't good because the identifiers should be unique for each element in the application.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    #my-element {
      background: yellow;
    }

  </style>
</head>
<body>
  <div id="my-element">Example text.</div>
</body>
</html>
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join