Tailwind CSS / Backgrounds, Borders, and Shadows

Styling Borders and Outlines

In this tutorial, you will learn how to style borders and outlines of HTML elements. The tutorial covers various border styles, widths, and colors, as well as how to apply outline…

Tutorial 2 of 5 5 resources in this section

Section overview

5 resources

Explains how to use Tailwind CSS to apply backgrounds, borders, and shadows.

1. Introduction

This tutorial aims to guide you through the process of styling borders and outlines of HTML elements using CSS. By the end of this tutorial, you will be familiar with various border styles, widths, and colors, and you will also learn how to apply outlines to HTML elements.

What you will learn:
- How to style borders
- How to style outlines

Prerequisites:
- Basic understanding of HTML and CSS

2. Step-by-Step Guide

Styling Borders

You can style borders using the CSS properties: border-style, border-width, and border-color. The border-style property has several values like solid, dashed, dotted, double, etc.

Example:

<div class="example">This is a div with a border.</div>
.example {
  border-style: solid;
  border-width: 5px;
  border-color: red;
}

In the example above, we've given the div a solid, 5-pixel wide, red border.

Styling Outlines

Outlines are similar to borders but they do not take up space, they are drawn above the content. You can style outlines using the CSS properties: outline-style, outline-width, and outline-color.

Example:

<div class="example">This is a div with an outline.</div>
.example {
  outline-style: dotted;
  outline-width: 3px;
  outline-color: blue;
}

In the example above, we've given the div a dotted, 3-pixel wide, blue outline.

3. Code Examples

Example 1: Styling Borders

<div class="borderExample">This div has a styled border.</div>
.borderExample {
  border-style: dashed;
  border-width: 2px;
  border-color: green;
}

In the code above, we have styled the border of the div to be dashed, 2 pixels wide, and green.

Example 2: Styling Outlines

<div class="outlineExample">This div has a styled outline.</div>
.outlineExample {
  outline-style: double;
  outline-width: 4px;
  outline-color: purple;
}

In this code, we have styled the outline of the div to be double, 4 pixels wide, and purple.

4. Summary

In this tutorial, we learned how to style borders and outlines of HTML elements using CSS. The next steps would be to explore more complex border and outline styles, and learn how to use the border-radius property for rounded borders.

Additional resources:
- MDN Web Docs - border
- MDN Web Docs - outline

5. Practice Exercises

Exercise 1: Style a div with a dotted, 5 pixel wide, orange border.

Solution:

<div class="exercise1">This is a div for exercise 1.</div>
.exercise1 {
  border-style: dotted;
  border-width: 5px;
  border-color: orange;
}

Exercise 2: Style a div with a solid, 7 pixel wide, black outline.

Solution:

<div class="exercise2">This is a div for exercise 2.</div>
.exercise2 {
  outline-style: solid;
  outline-width: 7px;
  outline-color: black;
}

Exercise 3: Style a div with a double, 10 pixel wide, cyan border and a dashed, 3 pixel wide, magenta outline.

Solution:

<div class="exercise3">This is a div for exercise 3.</div>
.exercise3 {
  border-style: double;
  border-width: 10px;
  border-color: cyan;
  outline-style: dashed;
  outline-width: 3px;
  outline-color: magenta;
}

For more practice, try styling borders and outlines of different HTML elements, like paragraphs, headings, and lists.

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Markdown to HTML Converter

Convert Markdown to clean HTML.

Use tool

Random Password Generator

Create secure, complex passwords with custom length and character options.

Use tool

Backlink Checker

Analyze and validate backlinks.

Use tool

MD5/SHA Hash Generator

Generate MD5, SHA-1, SHA-256, or SHA-512 hashes.

Use tool

PDF Compressor

Reduce the size of PDF files without losing quality.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help