- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use inline CSS style for an element in HTML?
Using inline CSS we can apply a distinct style to one HTML element at a time. This can be done using the style attribute. Inline CSS always overrides style properties determined in internal or external style sheets.
Syntax
<element style="mystyles">
Following are the examples…
Example
In the following example we are applying inline style defined within the style attribute of relevant element
<!DOCTYPE html> <html> <body> <p style="color:lightgreen;">Hello Everyone</p> <p style="color:red;">Welcome to Tutorialspoint</p> </body> </html>
On executing the above script the incline css get activated and applied to the elements in the text.
Using JavaScript
Using JavaScript, the style property can be used to set the inline css properties of a particular element.
Syntax
element_name.style
Example
In the following example we use the style object to set the css properties of a paragraph with the id Varma.
<!DOCTYPE html> <html> <body> <p id="varma">HELLO WORLD..!</p> <script> let p = document.querySelector('#varma'); p.style.color = 'red'; p.style.fontWeight = 'bold'; </script> </body> </html>
On running the above code, the elements in the text get applied with inline CSS
- Related Articles
- How to use inline CSS (Style Sheet) in HTML?
- How to use internal CSS (Style Sheet) in HTML?
- How to use CSS style in PowerShell HTML Output?
- How to style an hr element with CSS?
- How to use the tag to define style information for an HTML page?
- How to add an inline layer in HTML?
- How to define multiple style rules for a single element in CSS?
- How to set style display of an html element in a selenium test?
- How to specify the type of box used for an HTML element using CSS?
- Using more than one CSS classes for an element in HTML
- How to include inline JavaScript inside an HTML page?
- How to apply inline CSS?
- When to use an inline function in Kotlin?
- How to remove the space between inline/inline-block elements in HTML?
- How do we include an inline sub window in HTML?

Advertisements