# Tridactyl Tips & Tricks 1: Hint mode CSS selectors Hi! Welcome to the first Tridactyl Tips & Tricks newsletter, as mentioned in the previous Tridactyl newsletter. This newsletter is very experimental so any feedback you have would be appreciated. This first edition is going out to all sponsors on GitHub and Patreon. Later editions will only go out to sponsors on tiers **10 USD a month and higher**; I'm trying to raise a bit more revenue since GitHub will no longer double donations. I'll probably make each newsletter public after a couple of months as I don't like restricting knowledge needlessly, but I want there to be some incentive other than warm fuzzy feelings for people to donate money to Tridactyl. My initial plan is to write a chunky guide like this about once a month - planned topics include custom ex-commands with `:js` and `:jsb`, `:composite` and custom themes - and once I run out of big ideas I'll send out shorter emails with more random tips & tricks more often. In my experience, most people who use Tridactyl know a lot about computers in general, but don't know much about web technologies. These guides therefore will assume very little knowledge about JavaScript or the working of websites. They may assume some rudimentary knowledge of programming terminology. Please do let me know if I'm getting the balance right! I wasn't sure where to start with the tips so I've gone for one of the features of Tridactyl I use most frequently: custom hint modes that use custom CSS selectors to only show the most relevant hints on your favourite websites; for example, on a search engine you might only want search results to be hinted. Essentially, we'll learn how to create lines like the following ones from my RC file. ``` " Only hint search results on Google and DDG bindurl www.google.com f hint -Jc .rc > div > a bindurl www.google.com F hint -Jbc .rc > div > a bindurl ^https://duckduckgo.com f hint -Jc [class=result__a] bindurl ^https://duckduckgo.com F hint -Jbc [class=result__a] " Comment toggler for Reddit, Hacker News and Lobste.rs bind ;c hint -Jc [class*="expand"],[class="togg"],[class="comment_folder"] ```  We'll cover quite a lot of ground here so bear with me: 1. What a CSS selector does and why it's useful for hint modes 2. How to craft a CSS selector that only contains the links you want 3. Using this CSS selector in various hint modes 4. Binding these hint modes to keys 5. Binding these hint modes to keys only on certain websites If you already know how to do any of those steps you can just skip the corresponding section. Without further ado: # 1: Introduction to CSS selectors and why they're useful for hint modes CSS - "cascading style sheets" - control how a web page is displayed. Here is a simple CSS snippet: ```css p { color: pink; } ``` This file would make all the paragraphs (the `
` tags) on the page pink. Why do we care about this? The bit before the curly bracket - `p` - is a CSS selector. It tells the browser which parts of the page to apply the following styles to. Tridactyl can use this same technology to pick which elements of a page to hint with the syntax `:hint -c [CSS selector]`. For reasons of backwards compatibility, this also includes hints for any elements for which the page is listening for mouse click events with JavaScript; you can turn this off with the `J` flag so in practice you will usually see this invoked as `:hint -Jc [CSS selector]`. Selectors can be combined with some but not all hint modes - we will cover them in section 3. MDN has an excellent tutorial on CSS selectors here: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors . I highly recommend that you take the time to go through it. # 2: How to craft a CSS selector that only contains the elements you want In this section we'll make use of the Firefox web console to help us to find an initial CSS selector that selects the elements we want to hint and then improve it. If you skipped the MDN tutorial above, you can get by in this section by knowing that websites generally denote "types" of element with classes, e.g. `
` might denote text that has been written by a sponsor. CSS selectors select classes with a leading dot, e.g. `.advertorial`. Tags are selected simply with the name of the tag and can be combined with other selectors, e.g. `p.advertorial`. The next important thing to know is that you can select direct children of other selectors with the child operator, `>`. So, if there were any `` tags (i.e. links) within the advertorial, we can select them with `p.advertorial>a`. In sum, then, a hint mode for clicking on links within advertorials would be `:hint -Jc p.advertorial>a`.
With that out of the way, let's look at how to use the Firefox developer tools to craft the best CSS selector for your elements. For this example, I'll pretend that I want to hint the main articles on the [English Wikipedia homepage](https://en.wikipedia.org/wiki/Main_Page). Right click on one of the elements you want to hint and click "Inspect Element". A panel should appear; you want to look at the HTML panel and see if there is any discernible pattern to the tags surrounding the element you are interested in. Right click another element you want to hint and check that it is the same. For example, for me, the HTML looks a bit like this:
```
James Humphreys
...