How to Change Font Size using drop-down List in JavaScript ? Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report To change or set a font size for certain text, the fontSize property needs to be changed. The fontSize property sets or returns a list of fontSize names for text in an element.CSS font-size property is used to specify the font's height and size. It affects the size of an element's text. It has a medium default value and can be applied to any element.Syntax:element.style.fontSize = "value"To change the font size by option dropdown, Option values can be used to pass font size values into option tags.Syntax:<option value="px">Example 1: In the following example, the drop-down list has five options for font size: 8px, 10px, 14px, 20px, and 24px. When the user selects an option the event listener is updated to gfg div by setting its style.fontSize property to the selected value. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> How to change font size using drop-down list in JavaScript ? </title> <style> h1 { color: green; } option { font-size: 1rem; } </style> </head> <body> <div id="gfg"> <h1>Welcome To Geeksforgeeks!!</h1> <p> A Computer Science portal for geeks. It contains well written,well thought and well explained computer science and programming articles. </p> </div> <select id="gfg1"> <option value="8px">8px</option> <option value="10px">10px</option> <option value="14px">14px</option> <option value="20px">20px</option> <option value="24px">24px</option> </select> <script> const selectFontSize = document.getElementById("gfg1"); const updateElement = document.getElementById("gfg"); selectFontSize.addEventListener("change", function () { const selectedValue = selectFontSize.value; updateElement.style.fontSize = selectedValue; }); </script> </body> </html> Output:Example 2: In the following example, the drop-down list contains three options for font size: Small, Medium, and Large. When the user selects an option the event listener is updated to the gfg1 paragraph by setting its style.fontSize property to the corresponding value in the fontSizes object. HTML <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> Change font size using in JavaScript ? </title> <style> h1 { color: green; } option { font-size: 1rem; } </style> </head> <body> <div id="gfg1"> <h1>Welcome To Geeksforgeeks!!</h1> <p> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles. </p> </div> <label for="gfg">Select font size:</label> <select id="gfg"> <option value="small">Small</option> <option value="medium">Medium</option> <option value="large">Large</option> </select> <script> const selectFontSize = document.getElementById("gfg"); const updateElement = document.getElementById("gfg1"); const fontSizes = { small: "12px", medium: "16px", large: "20px", }; selectFontSize.addEventListener("change", function () { const valueSelect = selectFontSize.value; updateElement.style.fontSize = fontSizes[valueSelect]; }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Change Font Size using drop-down List in JavaScript ? saurabhkumarsharma05 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to change font style using drop-down list in JavaScript ? To change or set a font style for certain text, the fontFamily CSS property needs to be changed. The fontFamily property sets or returns a list of font-family names for text in an element. Syntax: object.style.fontFamily = "font" To change the font style by option dropdown: The font values can be pa 2 min read How to Get Selected Value in Dropdown List using JavaScript? A dropdown list is an HTML element that allows users to select one option from a list of options. The <select> and <option> tags are used to create dropdown lists in HTML. In this article, we will see how to get selected value from dropdown list using JavaScript.Basic HTML Structure for 2 min read How to change font-weight of a text using JavaScript ? In this article, we will set the font-weight of a text dynamically using JavaScript. Ti change the font weight dynamically, we use HTML DOM Style fontWeight property. Syntax: object.style.fontWeight = "value" Property Values: normal: The font weight is the default value.lighter: The font weight is t 1 min read How to set font size based on window size using JavaScript ? Given an HTML document and the task is to change the font-size based on the size of the window with the help of JavaScript. Approach 1:First convert the document element font sizes to em or % by using a function.Call this function on every resize of the window. It will change the font size based on 1 min read How to change font size using jQuery ? In this article, we will see how to change the font size of an element using jQuery. To change the font size of an element, we will use css() method. The css() method is used to change the style property of the selected element. Syntax: $(selector).css(property) Return value: It will return the valu 1 min read How to change Selected Value of a Drop-Down List using jQuery? We will change the default selected value of the dropdown using jQuery. In an HTML select tag, the default selected value is the value given to the first option tag. With jQuery, it is easy to change the selected value from a drop-down list. Below are the methods to change the selected value of a dr 3 min read How to Change Font Size using CSS? The CSS font-size property is used to change the font size of text. CSS font-size PropertyThe font-size property in CSS sets the size of the text of HTML elements. Values can be in pixels, percentages, em, rem etc.Syntaxfont-size: value;Example: We can use various font-size units like - em, smaller, 2 min read How to Change the Color of HTML Element in JavaScript? Changing the text color of an HTML element using JavaScript enhances the user experience by making content more interactive and visually engaging. By accessing and modifying the element's style properties through the DOM, we can dynamically update font colors based on user actions or events. For exa 2 min read Allow users to change font size of a webpage using JavaScript If you have seen some websites, especially some Indian government portals, you would have noticed three small buttons at the top rightmost corner of the page looking something like this: -A A A+. These buttons generally allow website users to change the font size of the entire page or a certain port 3 min read How to Change Font Size in HTML ? To change the font size of any text we can use the CSS font-size Property, or some HTML keywords have some fixed font size but we change them by using this CSS property. We can use style attributes in the HTML. As we know, HTML has no <font> tag, so we are using CSS style to add font size. The 2 min read Like