Creating a Card Layout in HTML
A "card" is a UI component used to display related information in a highly visual, contained block. By using basic HTML structuring and standard CSS properties like box-shadow and border-radius, you can create beautiful cards from scratch.
Cards are extremely popular in modern web design and are frequently used to list things like blog articles, feature sets, products, and user profiles.
Establishing the HTML Structure
To create a card, we typically use a parent element (such as a div) to act as the card's boundary. Inside, we might place an image at the top using the img tag, followed by a "card body" div to hold the text content securely:
Styling the Card container
The defining feature of a card is its "contained" look. We can accomplish this by using border-radius to round the corners, and applying a box-shadow to give it a sense of elevation off the page background:
Styling the Image
When placing an image at the top of a card, it's best to force it to span the entire width of the card. The object-fit property ensures the image scales correctly without warping:
Full Working Example
Below is a fully styled card. Notice the use of padding inside the .card-body class to keep the text away from the edges of the card: