Drawing primitives with CSS

Drawing primitives is the easiest and main case in graphic fundamentals. In CSS, it can be used in common cases such as adding details to buttons or any other DOM elements. Let's learn the basics of drawing primitives in CSS.

How to draw a rectangle/square

The easiest primitive to draw in CSS is a rectangle. Let's draw a simple rectangle using the following code:

HTML code:

<div class="rectangle"></div>

SASS code:

.rectangle
width: 100px
height: 200px
background: black

Compiled CSS:

.rectangle {
    width: 100px;
    height: 200px;
    background: black;
}

This will draw a rectangle in the browser as follows:

How to draw a rectangle/square

To draw a square, we need to create ...

Get Professional CSS3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.