lang and dir Attributes — HTML Technical Interview Questions & Answers

Declaring document language and text direction.

lang and dir Attributes

  • Declaring document language and text direction.
  • lang and dir Attributes 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: lang and dir Attributes: show it on a tag. id vs class if relevant.

Code Examples for lang and dir Attributes

lang and dir Attributes — 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>

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

How to Explain lang and dir Attributes to an Interviewer

What is lang and dir Attributes?

An HTML attribute Goes on the opening tag