While canvassing colleagues on whether headlines in the Guardian have become trashy or misleading, as a couple of readers have suggested, I was directed towards this: "Argentinian taxman puts squeeze on breast surgeons," which appeared online last week.

OK. That's not one readers might expect to find on the Guardian website. And several commenters took exception to the headline – in print and online – atop a story about the fourth police officer revealed to have spent many years undercover in the environmental movement, which ran on the Guardian's front page on 20 January: "Officer married activist he was sent to spy on."

On the comment thread under the story, one reader said: "Given that your commentators appear to base their comments entirely on the headline, any chance you could make them a little less misleading? As those of us who have read the article have noticed, they married after he told her he was a police officer."

Earlier in the week a reader wrote to say that he felt our headline writing was "sinking lower by the week". His examples were "Steve Bruce says Paul Ince once pulled a gun on Sir Alex Ferguson" (it was an air rifle) and "Sir Alex Ferguson doubts whether David Beckham will cut it at Tottenham". The reader was right. Ferguson had said that the loan period would not be long enough for him to have playing opportunities.

Writing good headlines is a cross between a craft and an art form. They should be eye-catching and clear, tempting a reader into a story but never promising what they can't deliver. Editors and subeditors know that they must – as the Guardian style guide says – use active verbs, avoid cliches unless you are minting one, and be funny but never too clever. Headlines do have their own lexicon, so using the word "gun" instead of air rifle is acceptable shorthand.

Web headlines bring more complexity. Search engine optimisation (SEO) is a method used to ensure that the primary function of a headline – to be read by as many people as possible – works online. That means headlines have to incorporate the keywords most likely to be picked up by internet search engines.

The Guardian's head of SEO says: "My job is to ensure two things. Firstly that our online headlines can stand up out of context. Unlike print, we can't dictate the ways in which readers encounter our headlines, and they exist permanently, robbing them of daily context. A lot of my job involves reminding editorial staff that the internet is an index rather than a daily newspaper, so 'good' print headlines are often bad for readers online. Subs sometimes complain that they feel that online readers are let down by prosaic headlines. In fact readers are more let down if they can't find an article or identify its content from within a search engine, RSS feed or tweet. Creativity on top of that clarity is the ultimate aim."

An experienced subeditor outlined some of the difficulties: "Writing headlines is an art, and we've all had to learn another art, that of writing them for the web, too. They're very different beasts: a print headline can be clever, must fit and ideally would also talk to any picture it accompanies, as well as not clash with other heads on the page or repeat words in other furniture on the page. All that plus getting the tone/sense of the story right is a big ask, and we do it hundreds of times a week."

A web headline must be SEO-friendly, so it's acceptable – even desirable – to repeat crucial keywords, which is massively counterintuitive for print subs. The old skill of writing clever headlines isn't necessarily appropriate. Most of the time two very different headlines have to be written for each piece and, she says: "Frankly it's a bloody miracle they aren't a bit more wrong a bit more often."