The style Attribute — HTML Technical Interview Questions & Answers

Inline CSS declared directly on an element.

The style Attribute

  • Inline CSS declared directly on an element.
  • The style Attribute is an HTML attribute — extra info on the opening tag. Example: class, id, href, src, alt, for, type. <p class="fail">Fail</p>
  • id is unique on the page. class can repeat. Don’t use the same id twice. Prefer class for CSS.
  • Trap: styling with id for everything. Trap: inline style when a class would do.

Technical Interview Tip: The style Attribute: show it on a tag. id vs class if relevant.

Code Examples for The style Attribute

The style Attribute — working example

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <meta name="description" content="HTML practice" />
    <title>Head and attributes</title>
  </head>
  <body>
    <p class="note" title="Tooltip" data-level="1">
      Attributes add machine-readable info; head holds metadata.
    </p>
  </body>
</html>

The style Attribute — head holds metadata; title/data-*/lang/dir (and careful event attributes) annotate elements.

How to Explain The style Attribute to an Interviewer

What is The style Attribute?

An HTML attribute Goes on the opening tag