Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

HTML & CSS IntroductionChapter 13. CSS: Styling Borders and Drawing Lines

border-radius

border-radius

Creating Rounded Corners with border-radius

The border-radius property is used for setting round-shaped corners. You can use the border-radius without setting border-style. When the element's background is not transparent, you can still see the round corners even though the border style is not defined.

Property Values

Usually, px or % are used for border-radius although you can use other length units.

px

Using px, you can specify a fixed radius size independent of the element size. This is useful when you want to keep the same radius for all boxes regardless of the box size.

border-radius with the px unit

%

Using %, you can specify a radius size relative to the element size. If you set 50% for all corners, the box becomes a complete circle.

border-radius with the % unit

Multiple Values

Like other border properties, you can set multiple values to set border-radius; however, the positions are different as border-radius adjusts the corner shapes (not borders).

When you set only one value, the radius size is applied to all corners. By setting multiple values, you can set different radius sizes for each corner of the element.

Two values

  • The first value is applied to the top left and bottom right corners.
  • The second value is applied to the top right and bottom left corners.
border-radius with two keywords

Three values

  • The first value is applied to the top left corner.
  • The second value is applied to the top right and bottom left corners.
  • The third value is applied to the bottom right corner.
border-radius with three keywords

Four values

Using four values, you can specify the radius size of each corner. The property values are set based on clockwise order starting from the top left.

  • The first value is applied to the top left corner.
  • The second value is applied to the top right corner
  • The third value is applied to the bottom right corner.
  • The fourth value is applied to the bottom left corner.
border-radius with four keywords

Practice

Objective:
Practice to set different border radius width with different number of values

1. Update the body section of the HTML file

Add the code below in the body section of the chapter13.html file. We are adding the bg-border-radius class to set the size and shape of each box as a base object style. The code for the styling will be explained in the next step.

We also add border-radius to the base object using the style attribute for each element so that we can customize the border-radius style for each element. This part of the CSS code is written in the HTML file below.

In the code below, we are wrapping each set of item groups using the <div> element with the display and flex-wrap properties to structure the results. We'll explain these properties in detail later. For now, just copy and paste the code.

chapter13.html
<h2>Border Radius</h2>
<div class="bg-border-radius">Original</div>
<h3>px</h3>
<div style="display: flex; flex-wrap: wrap;">
  <div class="bg-border-radius" style="border-radius: 5px;">5px</div>
  <div class="bg-border-radius" style="border-radius: 25px;">25px</div>
  <div class="bg-border-radius" style="border-radius: 50px;">50px</div>
</div>

<h3>%</h3>
<div style="display: flex; flex-wrap: wrap;">
  <div class="bg-border-radius" style="border-radius: 10%;">10%</div>
  <div class="bg-border-radius" style="border-radius: 25%;">25%</div>
  <div class="bg-border-radius" style="border-radius: 50%;">50%</div>
</div>

<h3>Multiple Values</h3>
<div style="display: flex; flex-wrap: wrap;">
  <div class="bg-border-radius" style="border-radius: 50% 10%;"><b>2 Values</b>: 50% 10%</div>
  <div class="bg-border-radius" style="border-radius: 50% 30% 10%;"><b>3 Values</b>: 50% 30% 10%</div>
  <div class="bg-border-radius" style="border-radius: 10% 20% 30% 50%;"><b>4 Values</b>: 10% 20% 30% 50%</div>
</div>
<hr>

2. Update the CSS file

Open the practice.css file and add new code for adding styles to the bg-border-radius class.

practice.css
.bg-border-radius{
  width: 250px;
  height: 250px;
  margin: 10px;
  padding: 10px;
  background-color: #B3EBEF;
  text-align: center;
  line-height: 250px;
}

3. Check the result with a browser

  • Open chapter13.html with a browser
  • You can see how different sizes for the border-radius are set with multiple property values.

You can also check the sample result here (Demo Site).

link


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Practice Wireframe Design in Figma

Practice Wireframe Design in Figma

Figma Design File Structure and Toolbar

Figma Design File Structure and Toolbar

How to Use Layout Control with the CSS display Property

Display Property

Incorporating Web Fonts and Google Fonts in Your Website

Web Font and Google Font

Practice Wireframe Design in Figma

Practice Wireframe Design in Figma

Figma Design File Structure and Toolbar

Figma Design File Structure and Toolbar

How to Use Layout Control with the CSS display Property

Display Property

Incorporating Web Fonts and Google Fonts in Your Website

Web Font and Google Font

Tags:

Borderline

Border Radius

HTML & CSS Introduction
Course Content

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;

Chapter 1. Overview of Website Development

How Websites Work?

Designing, Building and Publishing Websites

Designing Websites

Building Websites – Frontend and Backend Coding

Web App vs. Website

Frontend Coding

Web Framework and CMS

Publishing Websites (Hosting Services)

Chapter 2. Preparing for Website Coding

Two Key Tools to Start Coding Websites

How Browsers Display Web Pages

File Name Rules

Website Directory Structure

Absolute Path vs. Relative Path

Chapter 3. HTML Basics

What Is HTML?

HTML Element

Attribute

HTML Document Structure

Layout Semantics

Heading and Paragraph Tag

Text-Level Semantics

Space, Line-break and Tag in Content

Comments in HTML Document

Chapter 4. HTML: Add Links and Images

Overview of Adding Links and Images

Embed Images – <img>

Image File Format

Add Hyperlinks – <a>

Add Hyperlinks to Images

Add Hyperlinks to Specific Location on Web Page

Link Tag – <link>

Script Tag – <script>

Chapter 5. HTML: Create Lists and Tables

Create Lists

Create Tables

Combine Table Cells

Chapter 6. HTML: Create Forms

Create Forms

Create Text Input Forms and Submit Button

Radio Button and Checkbox

Select Box

Labels

Auto Complete and Disabled

Chapter 7. Bridging HTML and CSS

Block Element vs. Inline Element

Nesting Elements – Parent Elements and Child Elements

Div vs. Span

Global Attribute – Class, ID and Style

Accordion – <Details> and <Summary>

Chapter 8. CSS Basics

What Is CSS?

CSS Syntax

Where To Type CSS?

CSS Basic Selectors

Descendant Selector

Inheritance

Specificity

Reset CSS

Browser Developer Tools for CSS

Comments in CSS Document

Chapter 9. Web Design Basics

Design Element Representation in HTML and CSS

Key Design Points by CSS

Length

Color Code – HEX and RGB

Color Theme

Chapter 10. CSS: Sizing and Spacing

CSS Box Model

width and height

padding

margin

Margin and Padding for Specific Side

margin: auto

box-sizing

Chapter 11. CSS: Styling Text and Images

Text Styling Properties

font-size

color

font-family

Web Font and Google Font

font-weight and font-style

text-decoration

line-height and letter-spacing

text-align

vertical-align

Styling Images

float: left and right

Chapter 12. CSS: Styling Backgrounds

background-color

background-image

background-size

background-repeat

background-position

background-attachment

background (Multiple Properties)

Chapter 13. CSS: Styling Borders and Drawing Lines

border-style

border-color

border-width

border-radius

Border (Multiple Properties)

Borders on Specific Side

Border Radius on Specific Side

Chapter 14. CSS: Layout – Key Concepts and Display Property

Layout Before and After

Layout Key Design Points

Display Property

inline, block and inline-block

display: none

Chapter 15. CSS: Layout – Flex Box

Flex Box – display: flex

flex-direction

Main Axis and Cross Axis

flex-wrap

justify-content

align-items

align-content

align-self

flex-grow

flex-shrink

flex-basis

margin: auto with Flex Box

Inline Flex Box

Nested Flex Box

Chapter 16. CSS: Styling Lists

List Styling Properties

list-style-type

list-style-image

list-style-position

Chapter 17. Creating and Styling Components

Components and Layout

Buttons

Cards

Top Bar

Footer and Bottom Bar

Chapter 18. Completing Website Development

Website Structure Design

Live Server

Home (Landing) Page Development

Main (List) Page Development

Content (Detail) Page Development

Chapter 19. Publishing Websites

Key Steps to Publish Websites

Domain and DNS Server

Favicon

GitHub Pages

Chapter 20. Supplemental Topics

Horizontal Rule – <hr>

Line Break – <br>

Reserved Characters and HTML Entities

Non-breaking Space – &nbsp;