Languages
[Edit]
EN

CSS - create resizable element

0 points
Created by:
Marley-Marks
712

In this article, we would like to show you how to create resizable elements using CSS.

Quick solution:

.element {
    resize: both;
    overflow: auto;
}

or:

.element {
    resize: horizontal;
    overflow: auto;
}

or:

.element {
    resize: vertical;
    overflow: auto;
}

Warning: This solution was introduced to Microsoft Edge around 2020.

 

Practical examples

1. Resizable element in both directions

In this example, we set resize property value to both, so we can resize the element both vertically and horizontally.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    body {
        height: 150px;
    }

    .resizable {
        height: 100px;
        width: 100px;
        border: 2px solid;
        resize: both;		/*   <----- required   */
        overflow: auto;		/*   <----- required   */
    }

  </style>
</head>
<body>
  <div class="resizable"></div>
</body>
</html>

2. Horizontal only

In this example, we set resize property value to horizontal, so we can resize the element horizontally.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .resizable {
        height: 100px;
        width: 100px;
        border: 2px solid;
        resize: horizontal;		/*   <----- required   */
        overflow: auto;			/*   <----- required   */
    }

  </style>
</head>
<body>
  <div class="resizable"></div>
</body>
</html>

3. Vertical only

In this example, we set resize property value to vertical, so we can resize the element vertically.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    body {
        height: 200px;
    }

    .resizable {
        height: 100px;
        width: 100px;
        border: 2px solid;
        resize: vertical;		/*   <----- required   */
        overflow: auto;			/*   <----- required   */
    }

  </style>
</head>
<body>
  <div class="resizable"></div>
</body>
</html>

References

  1. resize - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. CSS - make element resizable
  2. CSS - create resizable div
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join