SyntaxStudy
Sign Up
Home CSS Reference width / height

width / height

property

Sets the width and height of an element. Accepts px, %, em, rem, vw, vh, or auto.

Syntax

width: value; height: value;

Example

css
.container {
    width: 1200px;
    max-width: 100%;
    min-width: 320px;
}

.hero {
    width: 100%;
    height: 100vh;      /* full viewport height */
    min-height: 400px;
}

.thumbnail {
    width: 150px;
    height: 150px;
    object-fit: cover;  /* for images */
}