Tillitsdone
down Scroll to discover

Understanding CSS Border-Bottom A Comprehensive Guide

Learn about the CSS border-bottom property, its use cases, and available options for styling the bottom border of elements.

Enhance your web design with this versatile property.
thumbnail

Introduction

The border-bottom property in CSS is a shorthand that sets the width, style, and color of an element’s bottom border. This property is useful for adding distinctive bottom borders to elements like headers, footers, or any other HTML elements, enhancing the overall look of your website.

Specification

The border-bottom property is defined in the CSS Backgrounds and Borders Module Level 3 specification. It combines the border-bottom-width, border-bottom-style, and border-bottom-color properties.

Syntax

border-bottom: border-width border-style border-color;

Breakdown of Syntax

  • border-width: Specifies the thickness of the border. You can use keywords like thin, medium, thick, or specific lengths like px, em, etc.
  • border-style: Defines the style of the border. Options include none, hidden, dotted, dashed, solid, double, groove, ridge, inset, and outset.
  • border-color: Sets the color of the border. You can use color names, hex values, RGB values, etc.

Examples

border-bottom: 1px solid black; /* 1px wide, solid black border */
border-bottom: 2px dotted red; /* 2px wide, dotted red border */
border-bottom: medium dashed blue; /* Medium-width, dashed blue border */

Global Values

border-bottom: inherit; /* Inherits from parent element */
border-bottom: initial; /* Sets to initial default */
border-bottom: revert; /* Reverts to user agent's default */
border-bottom: revert-layer; /* Reverts to user agent's default at specific layer */
border-bottom: unset; /* Resets to natural value */

Order of Values

The values (width, style, color) can be specified in any order, and one or two may be omitted:

border-bottom: 2px dashed; /* 2px wide, dashed border with default color */
border-bottom: dashed blue; /* Dashed blue border with default width */

Constituent Properties

The border-bottom property is a shorthand for:

  1. border-bottom-width:

    • Description: Sets the width of the bottom border.
    • Values: Keywords (thin, medium, thick) or lengths (px, em, etc.).
    • Default: medium
  2. border-bottom-style:

    • Description: Sets the style of the bottom border.
    • Values: none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset.
    • Default: none
  3. border-bottom-color:

    • Description: Sets the color of the bottom border.
    • Values: Any CSS color value.
    • Default: currentcolor (current text color of the element)

Example

border-bottom: 2px solid green;

This sets:

border-bottom-width: 2px;
border-bottom-style: solid;
border-bottom-color: green;

Important Notes

  • If any property is not specified, it defaults to its initial value.
  • If border-bottom-style is none, the border won’t be visible.

Values

The border-bottom property accepts various values for width, style, and color.

<border-width>

  • Keywords: thin, medium (default), thick
  • Length Values: Units like px, em, rem, etc.

Example:

border-bottom: 2px; /* Sets width to 2px */

<border-style>

  • Values: none (default), hidden, dotted, dashed, solid, double, groove, ridge, inset, outset

Example:

border-bottom: dashed; /* Sets style to dashed */

<border-color>

  • Values: Color names, hex values, RGB values, etc.

Example:

border-bottom: blue; /* Sets color to blue */

Combining Values

border-bottom: 2px dashed blue; /* 2px wide, dashed blue border */
border-bottom: thick solid green; /* Thick, solid green border */

Global Values

border-bottom: inherit; /* Inherits from parent element */

Important Notes

  • If border-style is omitted or set to none, the border won’t be visible.
  • At least one value must be specified for a visible border.

Formal Definition

The border-bottom property is a shorthand for setting the bottom border of an element. It combines border-bottom-width, border-bottom-style, and border-bottom-color.

Initial Value

  • border-bottom-width: medium
  • border-bottom-style: none
  • border-bottom-color: currentcolor

Applies To

All elements, including the ::first-letter pseudo-element.

Inherited

No, not inherited.

Computed Value

  • border-bottom-width: Absolute length or 0 if border-bottom-style is none or hidden.
  • border-bottom-style: As specified.
  • border-bottom-color: Resolved color.

Animation Type

  • border-bottom-color: Animates as a color.
  • border-bottom-style: Discrete animation.
  • border-bottom-width: Animates as a length.

Formal Syntax

border-bottom = <line-width> [||] <line-style> [||] [<color>]
<line-width> = [<length>] | thin | medium | thick
<line-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset

Important Notes

  • The order of values does not matter.
  • If border-bottom-style is not specified or set to none, the border won’t be visible.

Examples

Applying a Basic Bottom Border

HTML

<div class="example1">This box has a simple bottom border.</div>

CSS

.example1 {
border-bottom: 2px solid black;
background-color: lightgray;
padding: 20px;
text-align: center;
}

Applying a Dashed Bottom Border

HTML

<div class="example2">This box has a dashed bottom border.</div>

CSS

.example2 {
border-bottom: 3px dashed red;
background-color: lightblue;
padding: 20px;
text-align: center;
}

Applying a Double Bottom Border

HTML

<div class="example3">This box has a double bottom border.</div>

CSS

.example3 {
border-bottom: 5px double green;
background-color: lightyellow;
padding: 20px;
text-align: center;
}

Applying a Bottom Border with Inheritance

HTML

<div class="parent">
<div class="child">This box inherits the bottom border style from its parent.</div>
</div>

CSS

.parent {
border-bottom: 4px solid blue;
}
.child {
border-bottom: inherit;
background-color: lightcoral;
padding: 20px;
text-align: center;
}

Applying a Bottom Border with Global Values

HTML

<div class="example4">This box has a bottom border set to initial values.</div>

CSS

.example4 {
border-bottom: initial;
background-color: lightpink;
padding: 20px;
text-align: center;
}

Browser Compatibility

The border-bottom property is widely supported across all major browsers, including:

  • Google Chrome: Full support.
  • Mozilla Firefox: Full support.
  • Safari: Full support.
  • Microsoft Edge: Full support.
  • Internet Explorer: Full support from IE 4.0.

Ensure to test your web pages across different browsers to confirm consistent behavior.

Best Practices

  1. Use Consistent Styles: Keep your border styles consistent across your website for a cohesive look.
  2. Avoid Overuse: Overusing borders can make your design look cluttered. Use them sparingly to highlight important elements.
  3. Combine with Other Properties: Combine border-bottom with other CSS properties like padding, margin, and background-color to create well-structured layouts.
  4. Test Across Browsers: Always test your web pages across different browsers to ensure consistent appearance.

Frequently Asked Questions

What is the default value for border-bottom?

The default values for the constituent properties are:

  • border-bottom-width: medium
  • border-bottom-style: none
  • border-bottom-color: currentcolor

Can I animate the border-bottom property?

Yes, you can animate the border-bottom property. The border-bottom-color property animates as a color, border-bottom-style animates discretely, and border-bottom-width animates as a length.

What happens if I omit the border-bottom-style?

If you omit the border-bottom-style, it defaults to none, making the border invisible.

Can I inherit the border-bottom property from a parent element?

Yes, you can use the inherit value to inherit the border-bottom property from a parent element.

By following these guidelines and understanding the border-bottom property, you can enhance the visual appeal and structure of your web pages effectively.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.