Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Resizable Aspect Ratio</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script> <style> #img{width:200px;height:150px;background:#fff3e0 url('https://code.jquery.com/ui/1.13.2/themes/base/images/ui-icons_444444_256x240.png') center/60px no-repeat;border:1px solid #f6c343;} </style> </head> <body> <p>Resize this box — its width/height ratio stays locked.</p> <div id="img" class="ui-widget-content"></div> <script> $(function(){ $("#img").resizable({ aspectRatio: true }); }); </script> </body> </html>
Output