How to Make an SVG Scale With its Parent Container? Last Updated : 05 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report SVGs (Scalable Vector Graphics) are great for graphics that need to stay sharp on any screen. But by default, they don’t always scale automatically with their parent container — unless you use the right settings.In this article, you'll learn how to make an SVG resize and scale properly with its parent container using CSS and HTML.Why Scaling MattersSVGs are resolution-independent, but they won’t resize unless told to.This is important for responsive designs — especially on mobile and various screen sizes.1. By directly embed the SVGThis approach uses the <svg> tag within a parent container, making the image scalable based on the parent’s dimensions. HTML <html> <body> <div class="container" style="width: 30%; height: 20%; border: 1px dashed black;"> <svg width="100%" height="auto" viewBox="0 0 100 100"> <rect width="50" height="50" style="fill:rgb(0,170,0); stroke-width:1; stroke:rgb(0,0,0)" /> </svg> </div> </body> </html> In this exampleThe parent <div> is given a width of 30% and height of 20%, which makes it responsive to the screen size.The SVG element has its width="100%" and height="auto" so it scales with the parent container's width.The viewBox="0 0 100 100" defines a coordinate system, ensuring that the SVG scales proportionally.OutputMake an SVG Scale With its Parent Container2. By embedding SVG as an <img>In this approach, the SVG file is referenced using the <img> tag. The browser automatically adjusts the SVG’s aspect ratio when the screen size changes. HTML <html> <body> <div class="container" style= "width:80%; height:80%; border:1px dashed black;"> <!-- Put your own SVG image below --> <img src="E:\method-draw-image.svg" alt="Description of your SVG image" style="width:50%"> </div> </body> </html> In this exampleThe SVG file is referenced in an <img> tag, and the browser scales the image based on the width and height attributes provided.In this example, the width is set to 50%, meaning it will scale to fit half of the parent container's width.This approach is simpler but less flexible than directly embedding the SVG within the HTML. It’s a good option for static images, but it doesn’t allow for styling or interaction as easily.Output:Full Screen:Full ScreenMinimized Screen:Minimized ScreenComparing the Two MethodsMethodProsConsEmbed SVG Directly in HTML- Full control over styling and interactivity. - Best for dynamic content.- Requires more complex markup. - May not be as straightforward for simple use cases.Embed SVG as <img>- Simple to implement. - Easy for static content.- Limited styling or interactivity. - Less flexible for responsive designs.Conclusion To scale SVGs responsively, use the viewBox attribute to maintain proportional scaling without distortion. Choose between:Direct embedding for more control and interactivity.Using the <img> tag for a simpler, static solution.Both methods allow SVGs to scale effectively, ensuring they look great on all screen sizes. Comment More infoAdvertise with us Next Article How to Make an SVG Scale With its Parent Container? S Shreyasi_Chakraborty Follow Improve Article Tags : Web Technologies HTML CSS HTML-SVG Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read HTML Tutorial HTML stands for HyperText Markup Language. It is the standard language used to create and structure content on the web. It tells the web browser how to display text, links, images, and other forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS and JavaScript 11 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read Like