EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

CSS Inline Style

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » CSS Tutorial » CSS Inline Style

CSS Inline Style

Introduction to CSS Inline Style

Cascading Style Sheet or CSS is a style sheet language, which defines how an HTML page should be presented. It basically styles the presentation of a particular piece of markup language code. There are three ways to include CSS in any HTML code, which are, External, Internal and Inline. While we call the externally defined style sheet in our page in the External method, we define the style within <style />  in the same HTML code in the Internal method. It uses style attributes for styling elements. Internal CSS is included in the same HTML page, as it is used for styling the elements being used in the code.

How does CSS Inline Style Work?

In Inline style CSS, we style a particular element of the HTML code. In the case of Inline Style CSS, ‘style ‘is treated as an attribute of any particular element, which has various properties and is used for the unique styling of any HTML element. We will demonstrate the use of inline CSS through some examples:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. Using Inline CSS for Styling a Single Element

  • Code for a basic HTML page
  • Include HTML, head, body tags in accordance with the structure.
  • Within <body> tag, define a paragraph tag <p> and use style attribute to style the paragraph. This can be done like:

<p style="color:blue; font-size:50px; font-style: italic;">This is test for Inline CSS</p>

HTML Code:

<html>
<head>
<title>Inline CSS</title>
<h1>Demonstration Of  CSS Inline Style</h1>
</head>
<body>
<p style="color:blue; font-size:50px; font-style: italic;">This is test for Inline CSS</p>
</body>
</html>

Output:

CSS Inline Style 1-1

2. Using Inline CSS for Multiple Elements

  • Similar to example 1, we will create an HTML page with basic HTML tags.
  • Within body, we first define heading tag, i.e. <h1>. We style the <h1> tag using various properties like text-decoration, text-decoration-style, color, font-weight.

<h1 style="text-decoration: underline;text-decoration-style:double; color: crimson; font-weight: 400px;">Inline Styling for multiple elements</h1>

  • Next, we style the paragraph tag i.e. <p>, where we define the color, font-size, and font-style.

<p style="color:red; font-size:30px; font-style: italic;">This is test for Inline CSS</p>

HTML Code:

<html>
<head>
<title>Inline CSS</title>
<h1>Demonstration Of  CSS Inline Style</h1>
</head>
<body>
<h1 style="text-decoration: underline;text-decoration-style:double; color: crimson; font-weight: 400px;">Inline Styling for multiple elements</h1>
<p style="color:red; font-size:30px; font-style: italic;">This is test for Inline CSS</p>
</body>
</html>

Output:

CSS Inline Style 1-2

Note: In the above two examples, we have used various properties on style attribute, such a font-weight, text-decoration. There are various other properties that can be looked upon. It will be a good idea to create a sample HTML page, and try as many style properties as possible, for the purpose of awareness and ease.

3. Using Inline Style CSS for Styling a list in HTML

  • In this example, we will style an unordered list and customize each list item for a better understanding of the inline style in CSS.
  • Once we have created a basic structure for an HTML page, we will create a list within the body. Since it is an unordered list, we will use the tag <ul>. By default, each list item in an unordered list appears as a round bullet point. We will style this to be square bullet point:

<ul style="list-style:square;">

  • Now, we will customize each list item, i.e. <li> tag. Please note, when trying the code, more properties can be added to each element for trying out different styles.

<li style="color:blue; font-style: italic;">Styling first list item</li>
<li style="color: purple; font-size: 25px;">Styling second list item</li>
<li style="color: green; font-weight: 400px;">Styling third list item</li>

HTML Code:

<html>
<head>
<title>Inline CSS</title>
<h1>Demonstration Of  CSS Inline Style</h1>
</head>
<body>
<h1 style="text-decoration: underline;text-decoration-style:double; color: crimson; font-weight: 400px;">Inline Styling for multiple elements</h1>
<h2 style="background: royalblue; color: white; font-size: 40 px; margin: 100px; text-align:center;">Using Inline Style CSS in a list</h2>
<ul style="list-style:square;">
<li style="color:blue; font-style: italic;">Styling first list item</li>
<li style="color: purple; font-size: 25px;">Styling second list item</li>
<li style="color: green; font-weight: 400px;">Styling third list item</li>
</ul>
</body>
</html>

Output:

Styling a list in HTML

4. Using Inline Style CSS for Styling an Image

  • We can set various properties for an image, using inline style CSS.
  • In this example, we will be setting a border for the image. There are many more properties that can be explored while practicing.
  • After writing the basic elements of the HTML page, we will style<img> and use additional attributes to size the image according to our requirement.

<img style=" border: 5px solid royalblue; padding: 5px;" src="image.jpeg" height="425px" width="600px">

HTML Code:

<html>
<head>
<title>Inline CSS</title>
<h1>Demonstration Of  CSS Inline Style</h1>
</head>
<body>
<h1 style="text-decoration: underline;text-decoration-style:double; color: crimson; font-weight: 400px;">Inline Styling for multiple elements</h1>
<h2 style="background: royalblue; color: white; font-size: 40 px; margin: 10px; text-align:center;">Using Inline Style CSS for an image</h2>
<img style=" border: 5px solid royalblue; padding: 5px;" src="image.jpeg" height="425px" width="600px">
</body>
</html>

Output:

Styling an Image

So, in this article, there were various examples discussed, which show, how inline style CSS can be worked into one’s HTML project. However, if the project is a high level and requires strict styling, it is recommended that one must use an external style sheet. That not only eases the work but also structures the project appropriately. Inline CSS can be used if the project is small and very few elements, which are not dynamic in nature, require styling. Inline style CSS is a local level change which is limited to that element of that HTML page only. For defining styles on a global level, using External style sheets will be a better idea.

Recommended Articles

This is a guide to CSS Inline Style. Here we discuss the introduction and how does CSS inline style works along with the examples and code implementation. You may also look at the following articles to learn more –

  1. CSS Pagination
  2. Types of CSS Selectors
  3. CSS Font Properties
  4. text-align in CSS

CSS Training (9 Courses, 9+ Projects)

9 Online Courses

9 Hands-on Projects

61+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
CSS Tutorial
  • CSS
    • Introduction To CSS
    • What is CSS?
    • Uses Of CSS
    • Advantages of CSS
    • Career In CSS
    • CSS Commands
    • Is Css Case Sensitive
    • CSS object-fit
    • Types of CSS Selectors
    • CSS Radio Button
    • CSS Attribute Selector
    • CSS first child of class
    • CSS Selector nth Child
    • CSS Parent Selector
    • CSS Child Selector
    • CSS Not Selector
    • CSS Descendant Selector
    • CSS Inline Style
    • Checkbox CSS
    • CSS Appearance
    • CSS Font Properties
    • CSS font-variant
    • CSS Pagination
    • CSS Table Styling
    • CSS Table Cell Padding
    • CSS Padding Color
    • CSS Text Formatting
    • CSS for Text-Shadow
    • CSS text-stroke
    • CSS text-indent
    • CSS Rotate Text
    • CSS Text Color
    • CSS Center Div
    • CSS Arrow
    • CSS Arrow Down
    • CSS offset
    • CSS Cursor
    • CSS Layout
    • CSS Grid Layout
    • Button in CSS
    • CSS Button Border
    • text-align in CSS
    • CSS Horizontal Align
    • CSS Position
    • CSS Box Sizing
    • CSS box-shadow
    • CSS Text Underline
    • CSS Text Outline
    • CSS Blinking Text
    • Text Decoration CSS
    • CSS Vertical Align
    • CSS Word Wrap
    • CSS Padding
    • CSS Font Color
    • CSS Color Generator
    • CSS Margin Right
    • CSS Margin Color
    • CSS Color Codes
    • CSS Color Transparent
    • CSS Color Chart
    • CSS Link Color
    • CSS z-index
    • CSS Curved Border
    • CSS Border Left
    • CSS left
    • CSS Gradient Generator
    • Radial Gradient in CSS
    • CSS Shape Generator
    • CSS Triangle Generator
    • CSS background-color
    • CSS Background Image
    • CSS background-clip
    • CSS background-blend-mode
    • CSS Drop Shadow
    • CSS line height
    • CSS line break
    • Sticky Footer CSS
    • CSS Header Design
    • CSS Border Style
    • CSS Border Generator
    • Sticky Sidebar CSS
    • CSS Transparent Border
    • CSS Border Radius
    • CSS translate
    • CSS transform
    • CSS 3D Transforms
    • CSS Text Transform
    • CSS Transition Effects
    • CSS Transition Property
    • CSS Animation Transition
    • Negative Margin CSS
    • CSS Navigation Bar
    • CSS Overflow
    • CSS overflow-wrap
    • CSS Lists
    • CSS list-style
    • CSS Order
    • CSS Box Model
    • CSS Inner Border
    • CSS Icon
    • Menu Icon CSS
    • CSS Multiple Borders
    • Opacity in CSS
    • CSS Float Right
    • CSS Clear Float
    • CSS clip
    • CSS disabled
    • CSS Border Padding
    • Border Images in CSS
    • CSS Visibility
    • CSS Validator
    • CSS Clearfix
    • CSS Counter
    • CSS Letter Spacing
    • CSS root
    • CSS zoom
    • CSS calc()
    • CSS.supports()
    • CSS Loader
    • Media Query CSS
    • CSS @keyframes
    • CSS @bottom
    • CSS page-break-after Property
    • CSS page-break
    • CSS Position Fixed
    • CSS skew()
    • CSS Row
    • CSS Masking
    • CSS Scrollbar
    • CSS Overlay
    • CSS Important
    • CSS Cursor Hand
    • CSS Inherit
    • CSS Position Relative
    • CSS Compressor
    • CSS tricks
    • CSS Outline Property
    • CSS Flexbox Properties
    • CSS flex-direction
    • CSS content property
    • CSS Typography
    • CSS Formatter
    • CSS nowrap
    • CSS Column
    • GridView CSS
    • CSS Viewport
    • CSS Minify
    • CSS Combinators
    • CSS in React
    • CSS Matrix 
    • CSS Pseudo Elements
    • CSS Pseudo Classes
    • CSS Pointer Events
    • CSS Resize
    • CSS Inheritance
    • CSS Interview Questions
    • Cheat Sheet CSS
  • CSS3
    • What is CSS3?
    • CSS3 Interview Questions
    • Cheat sheet CSS3
  • sass
    • How to Install SASS
    • SASS Interview Questions
    • What is Sass
    • SASS Comments
    • Sass Variables
    • SASS Import
    • SASS if else
    • SASS Nesting
    • SASS @each
    • SASS @at-root
    • SASS @extend
    • SASS @media
    • SASS @for
    • SASS Map
    • SASS Selectors
    • SASS Color Functions
    • SASS Mixins

Related Courses

CSS Training Course

Bootstrap Training Course

JQuery Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - CSS Training (9 Courses, 9+ Projects) Learn More