The launch of HTML5 on 28th October 2014 was a much-applauded and welcomed development in the internet and finally put the nail in the coffin of XHTML2. A host of new elements and attributes had been promised with html5 and it certainly did deliver.

The new elements and attributes listed below are all developments of html5. I have neglected to describe the new markup which isn't supported by any of the major browsers because I'm keen only to show what is possible now. For futurologists, you can see some of these new-but-not-supported attributes at CSS-Tricks.


Squares

There are a number of ways to create a CSS square but I would like to focus on creating responsive shapes that can be appropriately re-sized depending on screen size. I have started with the most basic and concise code that I could find, building to more complex styling that encompasses images and text.

Basic Responsive Square

The first example is described by Jose Vargas at codeitdown.com and uses the padding-bottom property to set the height since percentages in paddings are calculated against the parent's width.

HTML

<div id="square1"></div>

CSS

#square1 {
   width: 44%;
   padding-bottom: 44%;
   overflow: hidden;
   background: #4679BD;
}

Example: Square 1

 

 

Alternative Responsive Square

The majority of responsive CSS shape techniques employ the :before and/or :after pseudo-element. The second example from Beth Soderberg demonstrates this.

HTML

<div id="square2"></div>

CSS

#square2 {
   width: 44%;
   background: #ca0164;
}

#square2 :before{
   content: "";
   display: block;
   padding-top: 100%;
}

Example: Square 2

 


Rectangles

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Circles

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Triangles

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Trapezium

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Parallelogram

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Pentagons

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Hexagons

By Chris Coyier on CSS-Tricks

HTML

<div id="hexagon"></div>

CSS

#hexagon {
	width: 100px;
	height: 55px;
	background: IndianRed;
	position: relative;
}
#hexagon:before { content: ""; position: absolute; top: -25px; left: 0; width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 25px solid IndianRed; } #hexagon:after { content: ""; position: absolute; bottom: -25px; left: 0; width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 25px solid IndianRed; }

Examples


Octagons

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.


Star (five-pointed)

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Star (six-pointed)

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.