Skip to main content

What does the style attribute do inside an HTML tag?

Suggest an edit

The style attribute inside an HTML tag adds inline CSS styles and affects the appearance of a specific element. It applies directly to the tag it is placed inside.

Example:

html
<p style="color: red; font-size: 20px;">Text</p>

Here, style sets for <p>:

  • color: red; - red text color
  • font-size: 20px; - font size

Features of the style attribute:

  • applies only to one specific element
  • has very high priority among regular CSS rules
  • used for targeted, one-off changes, but not suitable for large projects (the code becomes unreadable)

In short: style="" is a way to write CSS settings directly inside an HTML tag and instantly change the appearance of a specific element.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Suggest an edit