HTML onselect Event Attribute Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report The onselect event attribute works when some text has been selected in an element. It is the part of event attribute. It is basically activated when text within an input or textarea is selected and enhances user interaction by responding to text highlighting. Syntax: <element onselect = "script">Example 1: In this example, we will see the implementation of the above event attribute. HTML <!DOCTYPE html> <html> <head> <title>onselect event attribute</title> <style> h1 { color: green; } body { text-align: center; } input { padding: 30px; width: 30%; display: flex; margin: 10px 0 0 30%; } </style> <script> function Geeks() { alert("Text selected!"); } </script> </head> <body> <h1>GeeksforGeeks</h1> <h2>onselect event attribute</h2> Text Box: <input type="text" value="GeeksforGeeks: A computer science portal for geeks" onselect="Geeks()"> </body> </html> Output: OutputExample 2: In this example, we will see the implementation of the above event attribute with another example. HTML <!DOCTYPE html> <html> <head> <title>onselect Example</title> <style> body { text-align: center; margin: 50px; } h1 { color: green; } input { padding: 12px; width: 50%; margin: 19px auto; box-sizing: border-box; } </style> <script> function solve() { console.log("Text is selected") } </script> </head> <body> <h1>GeeksforGeeks</h1> <input type="text" value="Select this text" onselect="solve()"> </body> </html> Output: OutputSupported Tags<input type="file"> <input type="password"> <input type="text"> <textarea>Supported BrowsersGoogle Chrome 1 and aboveEdge 12 and aboveFirefox 6 and aboveOpera 12.1 and aboveSafari 1 and above Create Quiz Comment M manaschhabra2 Follow 2 Improve M manaschhabra2 Follow 2 Improve Article Tags : Misc Web Technologies HTML HTML-Attributes Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables10 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms5 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List15+ min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like