CSU Ram Head Logo

JTC 372

Web Design and Management

CSS centering

Centering a block element horizontally in a container:

A block element to be centered inside whatever contains it should have the following CSS declarations:

margin-right: auto;
margin-left: auto;

If an element is inline by default (e.g., an image), it can be made block with the following CSS declaration:

display: block

Centering text vertically in a container with display: flex: