arrow_back Back to Notebook
css
css
June 20, 2019

How to make a div fit the size of its children

You can make a div fit the size of its children by using display: inline-block

Example Usage

<div style="display:inline-block"><!--  this div will be same size as its child -->
    <p style="width:200px;height 500px;">some content</p>
</div>

Using display:inline-block

some text
hello

Without display:inline-block

some text
hello

Thanks for reading!

John Wiseman

Full-Stack Software Engineer building scalable digital solutions. specializing in modern web technologies and mission-critical systems.

© 2026 Wiseman Systems Pty. Ltd.

Navigation

Start a Conversation

Ready to discuss your next project? Let's build something extraordinary together.

Get in Touch