css to take only necessary width code example Example: make div the size of the text inside div { display: inline-block; }