Tooltips For Button Elements - Html - Stack Overflow

How are we doing? Please help us improve Stack Overflow. Take our short survey
    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs How are we doing? Take our short survey Tooltips for Button elements Ask Question Asked 14 years, 9 months ago Modified 2 years, 7 months ago Viewed 560k times 433

Is it possible to create a tooltip for an html button. Its the normal HTML button and there is no Title attribute as it is there for some html controls. Any thoughts or comments?

Share Improve this question Follow edited Mar 9, 2021 at 22:18 isherwood's user avatar isherwood 60.9k16 gold badges120 silver badges167 bronze badges asked Feb 10, 2010 at 16:00 SARAVAN's user avatar SARAVANSARAVAN 15k16 gold badges51 silver badges70 bronze badges Add a comment |

8 Answers 8

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 799

Simply add a title to your button.

<button title="Hello World!">Sample Button</button>

Share Improve this answer Follow edited Jan 5, 2017 at 23:10 Urda's user avatar Urda 5,4105 gold badges38 silver badges50 bronze badges answered Feb 10, 2010 at 16:06 Muad'Dib's user avatar Muad'DibMuad'Dib 29.1k5 gold badges57 silver badges71 bronze badges 5
  • 15 @EduardLuca, In my case tooltip really does no work on disabled buttons because Bootstrap sets pointer-events: none for disabled state. It should work if set pointer-events: auto directly to the element. – Vitalii Alekask Commented Sep 7, 2016 at 9:45
  • it's also that, the tooltip will aim to show bottom from where the mouse is. So if the target element is on the bottom right of the screen then the tooltip scrambles over the mouse pointer. More generally: the position of the tip isn't smart sometimes... but I guess that's just the browsers then. – gideon Commented Jul 21, 2017 at 6:21
  • 1 There are situations where tooltips are necessary, but it is important to consider your userbase when using the method in this answer. I used the title attribute for showing a keyboard shortcut for a button because shortcuts aren't necessary and touch only devices don't use keyboards. – Dave F Commented Jun 2, 2018 at 17:54
  • but this doesn't show tooltip when you use keyboard to focus the button, any other trick to handle this? I guess this is accessibility issue, no? – Nikhil Commented Oct 4, 2018 at 13:31
  • Reference: HTML Living Standard 3.2.6.1 The title attribute. – Ludovic Kuty Commented May 26, 2020 at 8:20
Add a comment | 48

both <button> tag and <input type="button"> accept a title attribute..

Share Improve this answer Follow answered Feb 10, 2010 at 16:03 Gabriele Petrioli's user avatar Gabriele PetrioliGabriele Petrioli 196k34 gold badges271 silver badges327 bronze badges 2
  • 1 What about for plain HTML links using <a> and href? – Aaron Franke Commented Jan 6, 2019 at 4:39
  • 3 @AaronFranke yes a tags as well as all tags support the title attribute. See developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes – Gabriele Petrioli Commented Jan 6, 2019 at 10:06
Add a comment | 38

Use title attribute. It is a standard HTML attribute and is by default rendered in a tooltip by most desktop browsers.

Share Improve this answer Follow edited Nov 27, 2019 at 15:18 answered Feb 10, 2010 at 16:03 skyman's user avatar skymanskyman 2,47217 silver badges16 bronze badges 0 Add a comment | 26

A button accepts a "title" attribute. You can then assign it the value you want to make a label appear when you hover the mouse over the button.

<button type="submit" title="Login"> Login</button>

Share Improve this answer Follow answered Dec 19, 2019 at 23:03 Félix Urrutia's user avatar Félix UrrutiaFélix Urrutia 2713 silver badges3 bronze badges 0 Add a comment | 14

For everyone here seeking a crazy solution, just simply try

title="your-tooltip-here"

in any tag. I've tested into td's and a's and it pretty works.

Share Improve this answer Follow edited Aug 24, 2018 at 11:08 Pac0's user avatar Pac0 22.9k9 gold badges72 silver badges80 bronze badges answered Mar 6, 2017 at 13:49 Davidson Lima's user avatar Davidson LimaDavidson Lima 84910 silver badges19 bronze badges 2
  • 2 @krillgar, I gave a general solution that works not only with button but other tags. My intention was reinforce this possibility. – Davidson Lima Commented Mar 30, 2017 at 15:55
  • 4 regarding your last comment, it's already what skyman's answer was saying years ago. – Pac0 Commented Aug 24, 2018 at 11:08
Add a comment | 2

The title attribute is meant to give more information. It's not useful for SEO so it's never a good idea to have the same text in the title and alt which is meant to describe the image or input is vs. what it does. for instance:

<button title="prints out hello world">Sample Buttons</button> <img title="Hms beagle in the straits of magellan" alt="HMS Beagle painting" src="hms-beagle.jpg" />

The title attribute will make a tool tip, but it will be controlled by the browser as far as where it shows up and what it looks like. If you want more control there are third party jQuery options, many css templates such as Bootstrap have built in solutions, and you can also write a simple css solution if you want. check out this w3schools solution.

Share Improve this answer Follow answered Oct 28, 2019 at 22:23 A. U. Crawford's user avatar A. U. CrawfordA. U. Crawford 211 bronze badge Add a comment | 2

If your button still doesn't show anything with title, check if your button is NOT disabled

Share Improve this answer Follow answered Jul 8, 2020 at 8:25 Eugene Ihnatsyeu's user avatar Eugene IhnatsyeuEugene Ihnatsyeu 1,53516 silver badges17 bronze badges Add a comment | -3

You should use both title and alt attributes to make it work in all browsers.

<button title="Hello World!" alt="Hello World!">Sample Button</button> Share Improve this answer Follow edited Nov 19, 2018 at 12:38 answered Nov 19, 2018 at 11:00 Sergey Gurin's user avatar Sergey GurinSergey Gurin 1,55316 silver badges14 bronze badges 3
  • 3 Why should you use both? – Andrei Cioara Commented Mar 31, 2019 at 20:14
  • because some browser use alt attribute and some title – Sergey Gurin Commented May 17, 2019 at 20:13
  • 13 Nonsense. The alt attribute is only valid for img, input type="image" and area tags. – Christoph Bach Commented Jun 4, 2019 at 16:06
Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • We'll Be In Touch - A New Podcast From Stack Overflow!
  • The app that fights for your data privacy rights
  • Featured on Meta
  • More network sites to see advertising test
  • We’re (finally!) going to the cloud!
  • Call for testers for an early access release of a Stack Overflow extension...
Visit chat

Linked

-1 Add tooltip programmatically on asp.net web page 12 can the alt attribute be used for an input type button 4 How add tooltip for disabed button ? (reactstrap) 2 HTML input tag: how to have lots of text for title attribute? 0 Is it possible to display the description of a button when hovered over? 0 Button Suggestion message 4 Tooltip on button click using jquery 2 The tooltips over buttons Jquery 3 ToolTip on button click 0 Adding a tip to button when button active in HTML 0 Changing the tooltip of button dynamically in html 4 Click to show CSS tooltip 7 Tooltip with buttons and image 0 How to display button in tooltip 0 how can i show a tooltip when click a button 0 how to add tooltip for wordpress button?

Hot Network Questions

  • What are rests in the realm of rhythm and melody?
  • If Fighting Initiate with Unarmed Fighting Style replaces the damage of a Monk's unarmed strike, does it replace the damage of a Radiant Sun Bolt?
  • caber in different expressions
  • Can a microwave antenna detect single microwave photons?
  • Printing clist out, but controlling whether there should be a \nobreakspace after “and”
  • When SG-1 arrives in 1969, why is it initially an "empty" gate room?
  • What are the ethical considerations regarding mandatory class participation?
  • Publishing an article despite the outcomes are not what we wanted
  • Sci-fi movie that starts with a man digging his way out of a crashed spacecraft and promptly being torn in half
  • Naive proof that subgroup of free group is free, what's wrong?
  • Is it a Db9 with a #11 or a D with a b9 and a #11?
  • how to stop using a command directly
  • Why doesn't Hotelling's law seem to apply to the stances taken by political parties?
  • Why the second C in "recyceln" is pronounced [k] instead of [ts]?
  • Counting points on line in QGIS
  • How did the Dutch Republic get sufficient timber to build its navies?
  • To “digitize” means to turn something into a digital format that was previously not digital. What to call changing one digital format into another?
  • How to make these changes in circuitikz?
  • Aeschylus quote about wind, sea, skies and sun rays
  • Does launch on warning assume incoming ICBMs carry nuclear warheads?
  • front derailleur cable routing
  • Are there any existing (indigenous) European languages with aspirated/unaspirated versions of consonants which are different phonemes?
  • When was Superman controlled by rock music?
  • Can the Attorney General, with a cooperating president, naturalize all undocumented immigrants?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Button Alt Text On Hover