Which HTML Attribute is Used to Define Inline Styles?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered
  • The style attribute in HTML is used to define the inline style within the HTMl tags.
  • Any style defined globally, such as styles specified in the <style> tag or in an external style sheet, will be overridden by the style attribute.
  • It belongs to the Global Attributes group and can be applied to any HTML element.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax

We can write the 'style' attribute followed by style definitions' like the color , font-size, text-alignment etc. inside the tags of any HTML element as folllows:

Syntax

Use Of The Style Attribute

Let us look at some examples for how to use HTML attribute to define inline styles.

Example

Output

This is a styled header

I am happy to read this line styled in red color

As we can see the examples given above do the following things:

  • change header color, font-size and position of HTML header
  • change the color of a paragraph in HTML
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Why You Shouldn’t Use Inline Styles

Here are some reasons why you should avoid using inline styles unless absolutely necessary:

  • They give the HTML source code more weight.
  • They're difficult to keep track of and manage. They make it difficult to read and debug HTML source code.
  • These inline styles can't be used anywhere else or in other words, they can't be reused for some other HTML element as we do in external style sheet styling.
  • Inline styles cannot be cached by browsers. As a result, the website takes longer to load and reply.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Browser Support

AttributeChromeIEFirefoxoperasafari
styleyesyesyesyesyes

Conclusion

  • The style attribute in HTML is used to define the inline style within the HTMl tags.
  • Since it overrides any style set globally, generally we prefer not to use it.
  • It is supported by most of the browsers.
  • In case we have very less usage of styling and CSS in HTML, then we can use style attribute.