Coughing up blood or blood-stained mucus is alarming. It might be due to a simple cause (severe bout of coughing, or respiratory infection, or a throat problem) but it can also be a sign of a number of lung diseases - including lung cancer. It should be investigated if it persists although a cause is not always found.
There is a wide range of possible causes of coughing up blood including: pneumonia, TB and other lung infections, bronchiectasis, clots in the lung (pulmonary embolism), vasculitis conditions, lung cancer, and others. It can occasionally accompany heart failure. It can also arise in the throat or elsewhere. It should be assessed by a respiratory physician in the first instance if it persists.
Dr McAlpine will assess the problem from your story, from examining you, and from chest x-ray before advising if any “next steps” are needed. These steps could include CT scan, urine and blood tests, ENT assessment, or bronchoscopy tests.