CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Inline Display


The inline value is one of its most common values. Elements with display: inline do not start on a new line and only take up as much width as their content requires. You cannot set the width or height of inline elements; these properties are determined by the content within them.


Example 1: Basic Inline Elements

CSS

/* style.css */
span {
  display: inline; /* This is the default for span, but shown for clarity */
  border: 1px solid red;
}

HTML

<p>This is a paragraph with a <span>span element</span> inside it.</p>

Explanation

In this example, the <span> element is an inline element. Notice how it flows within the text of the paragraph and does not force a line break. The border demonstrates that it only wraps around the content itself.


Example 2: Inline Links

/* style.css */
a {
  display: inline; /* Default for anchor tags */
  background-color: yellow;
}

HTML

<p>Click on this <a href="#">inline link</a> to learn more.</p>

Explanation

The anchor (<a>) tag is another default inline element. It sits neatly within the line of text, and any background color applied will only cover the area of its content.


Example 3: Images as Inline Elements

CSS

/* style.css */
img {
  display: inline; /* Images are inline by default */
  width: 50px; /* Note: width and height can be set on replaced inline elements like images */
}

HTML

<p>Here is some text with an <img src="image.png" alt="inline image"> inside.</p>

Explanation

Images (<img>) are also inline elements. They are placed within the flow of text. Unlike non-replaced inline elements, you can set width and height on an image.


Example 4: Ignoring Width and Height

CSS

/* style.css */
.inline-box {
  display: inline;
  width: 200px; /* This property will be ignored */
  height: 100px; /* This property will be ignored */
  background-color: lightblue;
}

HTML

<div>This is a div, and here is an <strong class="inline-box">inline strong element</strong>.</div>

Explanation

This example shows a <strong> element set to display: inline. The width and height properties are completely ignored by the browser because inline elements' dimensions are dictated by their content.


Example 5: Margin and Padding on Inline Elements

CSS

/* style.css */
.inline-spacing {
  display: inline;
  margin: 20px; /* Horizontal margin works, vertical does not affect line height */
  padding: 10px;
  background-color: lightgreen;
}

HTML

<p>An example of an <em class="inline-spacing">inline element with spacing</em> in a sentence.</p>

Explanation

For inline elements, horizontal margin and padding will push other elements away. However, vertical margin and padding will not affect the space between lines of text, though the background color will show the padding area.


Example 6: Forcing a Block Element to be Inline

CSS

/* style.css */
p {
  display: inline;
  background-color: #f0f0f0;
}

HTML

<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>

Explanation

By default, paragraph (<p>) elements are block-level. By setting display: inline, we force them to behave like inline elements, causing them to sit next to each other on the same line.


Example 7: Multiple Inline Elements

CSS

/* style.css */
.inline-item {
  display: inline;
  border: 1px solid blue;
  margin-right: 10px; /* Adds space between the elements */
}

HTML

<div class="container">
  <span class="inline-item">Item 1</span>
  <span class="inline-item">Item 2</span>
  <span class="inline-item">Item 3</span>
</div>

Explanation

This demonstrates how multiple elements with display: inline will render one after another horizontally, without any line breaks. The margin-right property is used to create a visual separation between them.