CSS Tutorial

Borders

Borders are visual elements that define the edges of elements on a web page. They can be used to improve the visual appeal of a design or to separate different sections of content.

Steps to Add Borders

  • Select the element you want to add a border to.
  • Open the CSS file for your web page.
  • Add the following CSS properties to the element's CSS declaration block:
    • border-width: This property defines the width of the border in pixels.
    • border-style: This property defines the style of the border. Examples of border styles include solid, dashed, and dotted.
    • border-color: This property defines the color of the border.
    • border-radius: This property defines the radius of the corners of the border.

Example

h1 {
  border-width: 1px;
  border-style: solid;
  border-color: black;
  border-radius: 5px;
}

This example will add a 1px wide, solid, black border with 5px rounded corners to all <h1> elements on the web page.

Key Concepts

  • Border width: The width of the border in pixels.
  • Border style: The style of the border, such as solid, dashed, or dotted.
  • Border color: The color of the border.
  • Border radius: The radius of the corners of the border.

Tips for Accessibility

  • Use borders sparingly to avoid creating visual clutter.
  • Ensure that borders are visible to users with low vision by using high-contrast colors.
  • Avoid using borders that are too wide or too thin, as this can make it difficult for users to see the content.